package cn.tedu.luban.account.main.rpc;

import cn.tedu.luban.account.api.AccountApi;
import cn.tedu.luban.account.main.service.AccountService;
import cn.tedu.luban.account.protocol.dto.AccountDTO;
import cn.tedu.luban.account.protocol.param.AccountCreateParam;
import cn.tedu.luban.account.protocol.param.AccountPayParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AccountApiImpl implements AccountApi {

    @Autowired
    private AccountService accountService;

    @Override
    public Long createAccount(AccountCreateParam accountCreateParam) {
        // 调用业务层，创建账户 result返回1创建成功 返回0创建失败
        Long result = 0L;
        try{
            result = accountService.createAccount(accountCreateParam);
        }catch(Exception e){
            log.error("新增失败，账号参数：{}",accountCreateParam);
        }
        return result;
    }

    @Override
    public AccountDTO getAccount(Long userId) {
        AccountDTO accountDTO = null;
        try{
            accountDTO = accountService.getAccount(userId);
        }catch(Exception e){
            log.error("获取信息失败，用户Id：{}",userId);
        }
        return accountDTO;
    }

    @Override
    public Long mockPayment(AccountPayParam param) {
        // 模拟支付，返回支付结果
        Long result = accountService.mockPay(param);
        return result;
    }
}
